﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace ClimateControl.Infrastructure.Service
{
    public static class ServiceHelper
    {
        #region Fields

        private static string endpointAddressFormat = "net.tcp://{0}:8005/ClimateControl";
        private static string windowsServiceName = "Climate Control Service";

        #endregion Fields

        #region Methods

        public static NetTcpBinding GetBinding()
        {
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);
            binding.OpenTimeout = new TimeSpan(0, 0, 5);
            binding.ReceiveTimeout = TimeSpan.MaxValue;
            binding.SendTimeout = new TimeSpan(0, 0, 5);
            binding.ReliableSession.Enabled = true;
            binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 0, 30);
            binding.ReliableSession.Ordered = true;
            return binding;
        }

        public static EndpointAddress GetEndpointAddress(string location)
        {
            string address = string.Format(CultureInfo.InvariantCulture, endpointAddressFormat, location);
            EndpointAddress endpoint = new EndpointAddress(address);

            return endpoint;
        }

        public static Uri GetUri(string location)
        {
            return new Uri(string.Format(CultureInfo.InvariantCulture, endpointAddressFormat, location));
        }

        public static string GetWindowsServiceName()
        {
            return windowsServiceName;
        }

        #endregion Methods
    }
}
